package cn.lizemin.config;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.context.annotation.Configuration;

/**
 * @author lzm
 * @version 1.0
 * @description: TODO
 * @date 2022/1/3 14:54
 */
@Configuration
@Aspect
public class MyAspectConfig {

    /**
     * 环绕通知才有proceedingJoinPoint
     * @param proceedingJoinPoint 进行中的连接点
     * @return
     * @throws Throwable
     */
//    @Around("execution(* cn.lizemin.service.*.*(..))")

//    within的作用：指定某个包下的所有方法都进行切入
//    @Around("within(cn.lizemin.service.impl.*)")

//
    @Around("@annotation(cn.lizemin.annotations.MyAdvice)")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("======环绕前置=======");
        System.out.println("当前执行类：" + proceedingJoinPoint.getTarget());
        System.out.println("当前执行的方法：" + proceedingJoinPoint.getSignature().getName());

//        执行目标方法，获取返回值
        Object result = proceedingJoinPoint.proceed();

        System.out.println("=======环绕后置======");
        return result;
    }

//    @Before("execution(* cn.lizemin.service.*.*(..))")
//    public void before(JoinPoint joinPoint) {
//        System.out.println("======前置操作=======");
//        System.out.println("当前执行目标类：" + joinPoint.getTarget());
//        System.out.println("当前执行目标类中的方法：" + joinPoint.getSignature().getName());
//
//    }
//
//    @After("execution(* cn.lizemin.service.*.*(..))")
//    public void after(JoinPoint joinPoint) {
//        System.out.println("======后置操作=======");
//        System.out.println("当前执行目标类：" + joinPoint.getTarget());
//        System.out.println("当前执行目标类中的方法：" + joinPoint.getSignature().getName());
//
//    }


}
